<?php	
	// Interface function	
	function oh_module_url($tokens) {
		global $oh_object_url;
		if (count($tokens)>0) {
			if ($tokens[0]=='tools') {
				return $oh_object_url;
			}
			if ($tokens[0]=='framework') {
				if (count($tokens)>1) {
					$tokens = implode("/",array_slice($tokens,1));
					return $oh_object_url->oh_url_framework()."/".$tokens;				
				} else {
					return $oh_object_url->oh_url_framework();				
				}				
			}
			if ($tokens[0]=='script') {
				return 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
			}
		}
		return 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];	
	} 

	// Option file required
	require_once(dirname(__FILE__)."/array-adv.php");
	//require_once($oh['path']."/modules/mysql/ezsql/mysql/ez_sql_mysql.php");
	
	// Main class of module
	class oh_class_url {		
		function oh_class_url() {
		}
		// restituisce url della cartella principale del framweork
		function oh_url_framework() {
			global $oh;

			$sk1 = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
			$sk2 = $_SERVER["SCRIPT_FILENAME"];			
			$sk3 = dirname($_SERVER["SCRIPT_FILENAME"]);
			$sk4 = dirname($oh['path']);			
			
			$a_sk1 = explode("/",$sk1);
			$a_sk2 = explode("/",$sk2);
			$a_sk3 = explode("/",$sk3);
			$a_sk4 = explode("/",$sk4);
			
			if ($sk3 == $sk4) {
				return dirname($sk1)."/oh.framework";
			}
			if (count($a_sk3)>count($a_sk4)) {
				$t3 = $sk3;
				$t4 = $sk4;
				$c 	= 0;
				while(($t3!=$t4)&&($c<10)) {
					$t3 = dirname($t3);
					$c++;
				}
				return aa_prog(dirname($sk1),$c)."/oh.framework";
			} else {
				$t3 = $sk3;
				$t4 = $sk4;
				$t 	= oh("string")->charmaxquot($t3,$t4);
				$tj1 = substr($t4,$t[1]);
				$k =  oh("string")->charmaxquot($tj1,dirname($sk1));
				return substr(dirname($sk1),0,$k[1]).$tj1."/oh.framework";			
			}
			/*
			echo '-'.$c;			
			echo '<br>';
			//echo aa_diff($sk1,$sk2,-1,0);
			echo aa_delta($sk1,$sk2,true)."<br/>";
			echo aa_diff($sk1,$sk2,0,-18,true);

			echo '<table border="1">';			
			for ($i=-19;$i<20;$i++) {
				echo '<tr>';
				echo '<td>'.$i.'</td>';
				echo '<td>'.@$sk1[$i+$d1].'</td>';
				echo '<td>'.@$sk2[$i+$d2].'</td>';
				echo '<td>'.@$sk3[$i+$d3].'</td>';
				echo '</tr>';
			}
			echo '</table>';			
			*/
			return $this->oh_cut($sk1).$this->oh_pls()."/oh.framework";
		}
		// ritaglia da
		function oh_cut($u) {
			return $u;	
		}
		function oh_pls() {
			return "";
		}
		// tools
		function sanitize($url) {
			if (substr($url,0,7) == "http://") {
				return $url;
			} else {
				return "http://".$url;
			}			
		}
	}
		
	// Main object of module
	global $oh_object_url;
	$oh_object_url = new oh_class_url();
?>
